package com.jy.api.domain;

import com.jy.api.signUpReq.pos.OpenNumReq;
import com.jy.api.util.TimeUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import javax.persistence.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * Created by xiaohua on 2019/5/8.
 */
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Slf4j
public class NumTransaction {

    @Id
    @Column(length = 11)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addTime;

    private String partitionName;

    private String numName;

    private String mobile;

    private String storeId;
    //预订时间
    private Date bookTime;

    private String empName;

    private String empId;

    private Date beginTime;

    private String rulesName;

    private Date endTime;

    private int ruleId;

    private int people;

    private int parId;

    private int numId;

    private boolean status = false;

    private String bookName;

    private Date cancelTime;

    private String inTime;

    private Double roomAmount;

    private boolean bookStatus=false;

    private String notice;
    public NumTransaction(OpenNumReq req) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        this.partitionName = req.getParName();
        this.numName = req.getNumName();
        this.mobile = req.getMobile();
        this.storeId = req.getStoreId();
        this.empName = req.getEmpName();
        this.empId = req.getEmpId();
        try {
            if (StringUtils.equals(req.getSource(), "BOOK")) {
                this.bookTime = simpleDateFormat.parse(req.getBookTime());
                this.bookStatus=true;
                this.cancelTime = simpleDateFormat.parse(req.getCancelTime());
            }
            this.beginTime = simpleDateFormat.parse(req.getBeginTime());
        } catch (ParseException e) {
           log.info("时间转换异常");
        }
        this.rulesName = req.getRuleName();
        this.ruleId = req.getRuleId();
        this.people = req.getPeople();
        this.parId = req.getParId();
        this.numId = req.getNumId();
        this.bookName = req.getBookName();
        this.bookStatus=false;
        this.notice=req.getNotice();
    }
}
